﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
using System.IO;
using System.IO.Ports;
using Microsoft.Office.Core;
using Excel = Microsoft.Office.Interop.Excel;
using MasterDatabase;

namespace Job_Assignment
{
    public partial class Form1 : SQL_APPL
    {
        MaterDatabase P_003_KeHoachSanXuatTheoLine_MasterDatabase;
        Button_Lbl PlanForLine_Create_BT;
        Button_Lbl PlanForLine_Empl_Asign_BT;

        public string P_003_KeHoachSanXuatTheoLine_Select_CMD = @"SELECT * FROM [JOB_ASSIGNMENT_DB].[dbo].[P_003_KeHoachSanXuatTheoLine] ";
        public string P_003_KeHoachSanXuatTheoLine_Init_Database_CMD = @"SELECT * FROM [JOB_ASSIGNMENT_DB].[dbo].[P_003_KeHoachSanXuatTheoLine] 
                                                      WHERE [Date] = ''";
        private bool P_003_KeHoachSanXuatTheoLine_Exist = false;

        ExcelImportStruct[] P_003_KeHoachSanXuatTheoLine_Excel_Struct;
        const int P_003_KeHoachSanXuatTheoLine_INDEX = 0;

        //private void Init_P_003_KeHoachSanXuatTheoLine_Excel()
        // {
            // if (P_003_KeHoachSanXuatTheoLine_Excel_Struct == null)
            // {
                // P_003_KeHoachSanXuatTheoLine_Excel_Struct = new ExcelImportStruct[8];
                // P_003_KeHoachSanXuatTheoLine_Excel_Struct[0] = new ExcelImportStruct(0, "PartNumber", "PartNumber", Excel_Col_Type.COL_STRING, 20, true);
                // P_003_KeHoachSanXuatTheoLine_Excel_Struct[1] = new ExcelImportStruct(1, "LineID", "LineID", Excel_Col_Type.COL_STRING, 20, false);
                // P_003_KeHoachSanXuatTheoLine_Excel_Struct[2] = new ExcelImportStruct(2, "LineName", "LineName", Excel_Col_Type.COL_STRING, 50, false);
                // P_003_KeHoachSanXuatTheoLine_Excel_Struct[3] = new ExcelImportStruct(3, "GroupID", "GroupID", Excel_Col_Type.COL_STRING, 20, false);
                // P_003_KeHoachSanXuatTheoLine_Excel_Struct[4] = new ExcelImportStruct(4, "Capacity", "Capacity", Excel_Col_Type.COL_INT, 20, false);
                // P_003_KeHoachSanXuatTheoLine_Excel_Struct[5] = new ExcelImportStruct(5, "Date", "Date", Excel_Col_Type.COL_DATE, 50, false);
                // P_003_KeHoachSanXuatTheoLine_Excel_Struct[6] = new ExcelImportStruct(6, "Demand", "Demand", Excel_Col_Type.COL_INT, 50, false);
                // P_003_KeHoachSanXuatTheoLine_Excel_Struct[7] = new ExcelImportStruct(7, "SoCa", "SoCa", Excel_Col_Type.COL_FLOAT, 50, false);
            // }
        // }

        private bool P_003_KeHoachSanXuatTheoLine_Init()
        {
            if (P_003_KeHoachSanXuatTheoLine_Exist == true)
            {
                if (tabControl1.TabPages.Contains(P_003_KeHoachSanXuatTheoLine_MasterDatabase.MasterDatabase_Tab) == false)
                {
                    tabControl1.TabPages.Insert(tabControl1.TabPages.Count, P_003_KeHoachSanXuatTheoLine_MasterDatabase.MasterDatabase_Tab);
                }
                tabControl1.SelectTab("P_003_KeHoachSanXuatTheoLine");
                return true;
            }
            P_003_KeHoachSanXuatTheoLine_Exist = true;
            // Init_P_003_KeHoachSanXuatTheoLine_Excel();
            P_003_KeHoachSanXuatTheoLine_MasterDatabase = new MaterDatabase(OpenXL, tabControl1, "P_003_KeHoachSanXuatTheoLine", P_003_KeHoachSanXuatTheoLine_INDEX, MasterDatabase_Connection_Str, 
                                                            P_003_KeHoachSanXuatTheoLine_Init_Database_CMD, P_003_KeHoachSanXuatTheoLine_Select_CMD,
                                                            3, P_003_KeHoachSanXuatTheoLine_Excel_Struct, filterStatusLabel, showAllLabel,
                                                            StatusLabel1, StatusLabel2, ProgressBar1);
            
            // Empl_Skill_List_MasterDatabase.MasterDatabase_GridviewTBL.dataGridView_View.Columns["Line_ID"].Frozen = true;
            P_003_KeHoachSanXuatTheoLine_MasterDatabase.MasterDatabase_GridviewTBL.GridView.BackgroundColor = Color.White;
            P_003_KeHoachSanXuatTheoLine_MasterDatabase.MasterDatabase_GridviewTBL.Import_BT.Visible = false;
            P_003_KeHoachSanXuatTheoLine_MasterDatabase.MasterDatabase_GridviewTBL.Delete_All_BT.Visible = false;

            //Dho-Fixme: Do we need to use the button "Check_BT"?
            PosSize possize = new PosSize();
            possize.pos_x = 200;
            possize.pos_y = 90;
            PlanForLine_Create_BT = new Button_Lbl(1, P_003_KeHoachSanXuatTheoLine_MasterDatabase.MasterDatabase_Tab, "Create", possize, (AnchorStyles)AnchorStyles.Left | AnchorStyles.Top);
            PlanForLine_Create_BT.My_Button.Click += new EventHandler(PlanForLine_Create_BT_Click);

            possize.pos_x = 300;
            possize.pos_y = 90;
            PlanForLine_Empl_Asign_BT = new Button_Lbl(2, P_003_KeHoachSanXuatTheoLine_MasterDatabase.MasterDatabase_Tab, "Assign", possize, (AnchorStyles)AnchorStyles.Left | AnchorStyles.Top);
            PlanForLine_Empl_Asign_BT.My_Button.Click += new EventHandler(PlanForLine_Empl_Asign_BT_Click);

            //<<Long_15_06
            DataGridViewMultiColumnComboBoxColumn col = new DataGridViewMultiColumnComboBoxColumn();
            col.Name = "Empl_ID";
            col.DataPropertyName = "Empl_ID";
            col.ValueMember = "Empl_ID";
            //col.DataSource = dtThreeShiftGroup;
            //col.ValueMember = "GroupName";
            //col.ColumnNames = new List<string> { "GroupName" };
            //col.ColumnWidths = new List<string>() { "200" };

            if (P_003_KeHoachSanXuatTheoLine_MasterDatabase.MasterDatabase_GridviewTBL.GridView.Columns.Contains("Empl_ID"))
            {
                int index = P_003_KeHoachSanXuatTheoLine_MasterDatabase.MasterDatabase_GridviewTBL.GridView.Columns["Empl_ID"].Index;
                P_003_KeHoachSanXuatTheoLine_MasterDatabase.MasterDatabase_GridviewTBL.GridView.Columns.RemoveAt(index);
                P_003_KeHoachSanXuatTheoLine_MasterDatabase.MasterDatabase_GridviewTBL.GridView.Columns.Insert(index, col);
            }
            //>>Long_15_06

            return true;

        } 
    }
}